﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Infragistics.Windows.Chart;

namespace CCSManager
{
	/// <summary>
	/// Interaction logic for AppUsage.xaml
	/// </summary>
	public partial class AppUsage : Window
	{
		public AppUsage(AppStatus aps)
		{
			this.InitializeComponent();
            Closed += new EventHandler(AppUsage_Closed);
		}

        void AppUsage_Closed(object sender, EventArgs e)
        {
            App.Current.Shutdown();
        }

	    private Dashboard m_db;

        public AppUsage(Dashboard db, AppStatus appStatus)
        {
            this.InitializeComponent();
            Closed += new EventHandler(AppUsage_Closed);

            m_db = db;
            var rgbRand = new Random(DateTime.Now.Second);

            // Generate a random color
            byte red = Convert.ToByte(rgbRand.Next(0, 255));
            byte green = Convert.ToByte(rgbRand.Next(0, 255));
            byte blue = Convert.ToByte(rgbRand.Next(0, 255)); var ani = new Animation { BeginTime = new TimeSpan(0, 0, 1), Duration = new Duration(new TimeSpan(0, 0, 5)) };
            var combinedRevOverTime = new Series { Animation = ani, Label = appStatus.AppName, ChartType = ChartType.Line, StrokeThickness = 3, Fill = new SolidColorBrush(Color.FromRgb(red, green, blue)) };
            foreach (AppSalesData asd in appStatus.AppSalesData)
            {
                string label = asd.Reported.ToString("M/yy");
                combinedRevOverTime.DataPoints.Add(new DataPoint { Label = label, Value = Convert.ToDouble(asd.Revenue) });
            }
            CombinedRevenueOverTimeChart.Series.Add(combinedRevOverTime);
        }

        private void BackToDbButton_Click(object sender, RoutedEventArgs e)
        {
            foreach (object window in Application.Current.Windows)
            {
                ((Window)window).Hide();
            }
            m_db.Show();
            m_db.Topmost = true;
        }

        private void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            var loginWindow = new Login { Left = Left, Top = Top };
            foreach (object window in Application.Current.Windows)
            {
                ((Window)window).Hide();
            }
            loginWindow.Show();
        }
	}
}